﻿Imports System.Data.SqlClient

Public Class clsHorariosDiesel
    Private mintIdHorario As Integer
    Private mintIdAutobus As Integer
    Private mdatFecha As Date
    Private mdatULTIMA_FECHA_HORA As DateTime
    
    Public Property IdHorario() As Integer
        Get
            Return mintIdHorario
        End Get
        Set(ByVal value As Integer)
            mintIdHorario = value
        End Set
    End Property
   
    Public Property IdAutobus() As Integer
        Get
            Return mintIdAutobus
        End Get
        Set(ByVal value As Integer)
            mintIdAutobus = value
        End Set
    End Property
    Public Property Fecha As Date
        Get
            Return mdatFecha
        End Get
        Set(ByVal value As Date)
            mdatFecha = value
        End Set
    End Property
    Public Property ULTIMA_FECHA_HORA() As DateTime
        Get
            Return mdatULTIMA_FECHA_HORA
        End Get
        Set(ByVal value As DateTime)
            mdatULTIMA_FECHA_HORA = value
        End Set
    End Property

    Public Sub New()
        mintIdHorario = 0
        mintIdAutobus = 0
        mdatFecha = Now()
        mdatULTIMA_FECHA_HORA = Now()
    End Sub
    Public Sub Insertar()
        Dim sql As String = "Insert Into HorariosDiesel (" & _
                            "IdHorario," & _
                            "IdAutobus," & _
                            "Fecha," & _
                            "ULTIMA_FECHA_HORA)" & _
                            "VALUES (" & _
                            "@IdHorario," & _
                            "@IdAutobus," & _
                            "@Fecha," & _
                            "@ULTIMA_FECHA_HORA)"
                            

        Dim cnConn As New SqlConnection
        cnConn.ConnectionString = CitraConnection

        Dim Command As New SqlCommand(sql, cnConn)

        Command.Parameters.AddWithValue("IdAutobus", mintIdAutobus)
        Command.Parameters.AddWithValue("Fecha", mdatFecha)
        Command.Parameters.AddWithValue("ULTIMA_FECHA_HORA", mdatULTIMA_FECHA_HORA)
       

        cnConn.Open()
        Dim RowsAffected As Integer = Command.ExecuteNonQuery

        If RowsAffected > 0 Then
            cnConn.Close()
        Else
            MsgBox("No fue posible insertar la Liquidacion ", MsgBoxStyle.Exclamation, "Aviso")
            If cnConn.State = ConnectionState.Open Then
                cnConn.Close()
            End If
        End If
    End Sub
  
End Class
